<?php

session_start();
include ('../Fonctions.php');

$infoConvention = array(
    $agissant = trim(htmlspecialchars(strip_tags($_POST['personneERDF']))),
    $endroit = trim(htmlspecialchars(strip_tags($_POST['endroitERDF']))),
    $date = trim(htmlspecialchars(strip_tags($_POST['dateARF85ERDF']))),
    $pdf = trim(htmlspecialchars(strip_tags($_POST['valider']))));

if (isset($_POST['soussigne1'])) {
    $soussigne = trim(htmlspecialchars(strip_tags($_POST['soussigne1'])));
} else {
    $soussigne = "null";
}

$i = 2;
while (isset($_POST['soussigne' . $i])) {
    ${"soussigne" . $i} = trim(htmlspecialchars(strip_tags($_POST['soussigne' . $i])));
    $soussigne .= "_" . ${"soussigne" . $i};
    echo ${"soussigne" . $i} . "<br />   ";
    $i++;
}
echo $soussigne;

foreach ($infoConvention as $info) {
    echo $info . "<br />";
}

$insertionARF85ERDF->execute(array(
    'type_etude' => "municipalite",
    'id_etude' => $_SESSION['id_etude'],
    'nom_convention' => "ARF85 ERDF",
    'nom_soussigne' => $soussigne,
    'proprio' => $agissant,
    'lieu' => $endroit,
    'date' => $date
));

if ($pdf == "PDF/") {
    $infosTemp = $bdd->prepare("SELECT id_convention_arf85_erdf FROM convention_arf85_erdf WHERE type_etude = :type_etude AND id_etude = :id_etude AND 
            nom_soussigne = :nom_soussigne AND proprio = :proprio AND lieu = :lieu AND date = :date");
    $infosTemp->execute(array(
        'type_etude' => "municipalite",
        'id_etude' => $_SESSION['id_etude'],
        'nom_soussigne' => $soussigne,
        'proprio' => $agissant,
        'lieu' => $endroit,
        'date' => $date
    ));
    $temp = $infosTemp->fetch();

    header('Location: ../conventionARF85ERDF.php?typeEtude=municipalite&idEtude=' . $_SESSION['id_etude'] . '&idConvention=' . $temp['id_convention_arf85_erdf'] . '&pdf=oui');
}
?>
